package 缺失的第一个正数;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = new int[]{7,8,9,11,12};
        System.out.println(solution.firstMissingPositive(nums));
    }

    public void swap(int[] nums,int index){
        int a = nums[index];
        if(a > 0 && a - 1 < nums.length && nums[a-1] != a){
            int temp = nums[a-1];
            nums[a-1] = a;
            nums[index] = temp;

            swap(nums,index);
        }

    }

    public   int firstMissingPositive(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            swap(nums,i);
        }


        for (int i = 0; i < nums.length; i++) {
            if(i != nums[i]-1){
                return i+1;
            }
        }

        return nums.length+1;
    }


}
